package com.heima.admin.controller.v1;

import com.heima.admin.service.AdSensitiveService;
import com.heima.model.admin.dtos.SensitiveDto;
import com.heima.model.admin.pojos.AdSensitive;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 1、接收前端请求
 * 2、调用Service（业务逻辑）
 * 3、返回结果
 * @Description:
 * @Version: V1.0
 *
 * code:
 * 400： 前端传递参数有问题
 * 404： 前端url路径有问题
 * 405： 请求方式不匹配
 *
 */
@Api(value = "敏感词管理", tags = "sensitive", description = "敏感词管理API")
@RestController
@RequestMapping("/api/v1/sensitive")
public class AdSensitiveController {


    @Autowired
    AdSensitiveService sensitiveService;


    @ApiOperation("敏感词分页查询")
    @PostMapping("list")
    public ResponseResult findByNameAndPage(@RequestBody SensitiveDto dto ) {
        return sensitiveService.findByNameAndPage(dto);
    }


    @ApiOperation("敏感词新增")
    @PostMapping("save")
    public ResponseResult insert(@RequestBody AdSensitive adSensitive) {
        return sensitiveService.insert(adSensitive);
    }

    @ApiOperation("敏感词修改[修改敏感词状态]")
    @PostMapping("update")
    public ResponseResult update(@RequestBody AdSensitive adSensitive) {
        return sensitiveService.update(adSensitive);
    }


    @ApiOperation("根据ID删除敏感词")
    @DeleteMapping("del/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id) {
        return sensitiveService.delete(id);
    }


}
